/**
 * @file mock模拟数据
 *
 * @author liubin29(liubin29@baidu.com)
 * 2017年3月28日
 */

let fs = require('fs');
let path = require('path');

let filepath = path.resolve(__dirname + '/../.tmp');

module.exports = function* (next) {
    if (this.request.body) {
        if (!fs.existsSync(filepath)) {
            fs.mkdirSync(filepath);
        }

        let body = this.request.body;
        body.pageId = this.params.pageId;
        fs.writeFileSync(filepath + '/' + this.params.pageId + '.json', JSON.stringify(body));

        this.body = {
            status: 0,
            statusInfo: '',
            data: ''
        };
    }
    else {
        yield next;
    }
};
